//
// Created by Lee on 2019/2/17.
//
#include <stdio.h>
#include "com_example_jnidemo_JniTest.h"
#include "android/log.h"

#define LOG_TAG "JNI_TEST"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

JNIEXPORT jstring JNICALL Java_com_example_jnidemo_JniTest_jniHelloWorld
        (JNIEnv *env, jobject obj) {
    float a = 10;
    LOGE("我是C代码中的日志 a=%f",a,a);
    return (*env)->NewStringUTF(env, "JNI helloworld");
}

JNIEXPORT jint JNICALL Java_com_example_jnidemo_JniTest_getStringFormc
(JNIEnv *env,jobject s,jint x,jint y){
    LOGE("%s","okokoko");
    //1.获取jclassD:\workplace\JNIDemo\app\src\main\java\com\example\jnidemo
    char* className = "com/example/jnidemo/JniTest";
    jclass dpclazz = (*env)->FindClass(env,className);

    if (dpclazz==NULL){
        printf("%s","dpclass not find");
    }
    //2.调用GetMethodID来获取methodid
    jmethodID methodID = (*env)->GetStaticMethodID(env,dpclazz,"add","(II)I");
    //3.调用CallTypeMethod来调用相应的方法，执行java方法
    jint result = (*env)->CallStaticIntMethod(env,dpclazz,methodID,x,y);
    return result;
}

JNIEXPORT void JNICALL Java_com_example_jnidemo_JniTest_getStudents
(JNIEnv *env,jobject object,jobject objectList) {
    char* classname = "com/example/jnidemo/MainActivity";
    jclass clazz = (*env)->FindClass(env,classname);
    if (clazz == NULL){
        printf("%s","not find class\n");
    }

//    jclass cls_list = (*env)->GetObjectClass(env,objectList);//获得jclass
//    if (cls_list == NULL){
//        printf("%s","not find class\n");
//    }
    //getmethodid
    jmethodID methodID = (*env)->GetMethodID
            (env,clazz,"initStudents","()Ljava/util;");
    if (methodID == NULL){
        printf("%s","not find initStudents method");
    }

    //在c语言中调用相关方法，CallTypeMethod,其中Type随着返回值类型的不同而改变

}
